package com.flashflexpro.flexdirector.model{


import mx.collections.ArrayCollection;

[Bindable]
[RemoteClass]
public class DtoTestSuite extends NameAndComment{
    
    public var lastSaveTime:int;

    public function DtoTestSuite( ) {
        name = "Unnamed test suite";
        cases = new ArrayCollection();
        procedures = new ArrayCollection();
        applications = new ArrayCollection();
    }

    [ArrayElementType("com.flashflexpro.flexdirector.model.DtoTestCase")]
    public var cases:ArrayCollection = new ArrayCollection();


    [ArrayElementType("com.flashflexpro.flexdirector.model.DtoTestProcedure")]
    public var procedures:ArrayCollection = new ArrayCollection();


    [ArrayElementType("com.flashflexpro.flexdirector.model.DtoApp")]
    public var applications:ArrayCollection = new ArrayCollection();

    /**
     * only recording app insts!
     */
    [ArrayElementType("com.flashflexpro.flexdirector.model.DtoAppInstRecording")]
    public var recordingAppInsts:ArrayCollection = new ArrayCollection();

    override public function treeWalk(nodeFunc:Function, self:Object=null, parent:NameAndComment = null):void {
        super.treeWalk(nodeFunc, self, parent );
        var counter:int;
        if (cases != null) {
            for (counter= 0; counter < cases.length; counter ++) {
                ( cases.getItemAt(counter) as NameAndComment ).treeWalk(nodeFunc, self, this );
            }
        }
        if( procedures != null ){
            for (counter = 0; counter < procedures.length; counter ++) {
                ( procedures.getItemAt(counter) as NameAndComment ).treeWalk(nodeFunc, self, this );
            }
        }
        if( applications != null ){
            for (counter = 0; counter < applications.length; counter ++) {
                ( applications.getItemAt(counter) as NameAndComment ).treeWalk(nodeFunc, self, this );
            }
        }
        if( recordingAppInsts != null ){
            for (counter = 0; counter < recordingAppInsts.length; counter ++) {
                ( recordingAppInsts.getItemAt(counter) as NameAndComment ).treeWalk(nodeFunc, self, this );
            }
        }
    }

    public function deleteRecordingAppInst( inst:DtoAppInstRecording ):void{
        var index:int = recordingAppInsts.getItemIndex( inst );
        if( index < 0 ){
            throw new Error( inst+ " not belongs to this suit!" );
        }
        inst.destroy();
        recordingAppInsts.removeItemAt( index );
    }


    public function getAppInstReplayByApp( app:DtoApp, rt:ArrayCollection):void{
        if( rt == null ){
            rt = new ArrayCollection();
        }
        else{
            rt.removeAll();
        }
        for each( var procedure:DtoTestProcedure in procedures ){
            for each( var obj:* in procedure.children ){
                var replay:DtoActionReplay = obj as DtoActionReplay;
                if( replay != null && replay.appInst.app == app && !rt.contains( replay.appInst )){
                    rt.addItem( replay.appInst );
                }
            }
        }
    }
}
}